// node 44_定时器输出.js

//每次间隔a，a+b,a+2b,a+nb的时间
//执行fn函数，执行n次后，自动关闭定时器


function MySetInterval(fn,a,b,n) {
    this.fn = fn
    this.a = a
    this.b = b
    this.n = n
    this.count = 0
    this.timeout = null
}
MySetInterval.prototype.Interval = function () {
    let time = this.a + this.b * this.count
    this.timeout = setTimeout(() => {
        this.fn();
        this.count++
        this.Interval()
        console.log(time)
    }, time)
    if(this.count+1 > this.n){
        console.log('关闭定时器')
        clearTimeout(this.timeout)
    }
}

let fn = function(){console.log('fn')}
let myTime = new MySetInterval(fn,1000,2000,3)
myTime.Interval()